import store from '@/store'
import router from '@/router'
const whiteList = ['login']
// 是否已经动态添加路由
let hasRoute = false
router.beforeEach(async (to, from, next) => {
   // 白名单
   if (whiteList.includes(to.name)) {
      next()
   }
   if (!store.getters.token) {
      // 判断是否已经是在login页面，如果不是则跳转到login页面
      if(to.path !== '/login'){
         next({path: '/login'})
      }
   } else {
      if (!hasRoute) {
         hasRoute = true
         next({ ...to, replace: true })
      }
   }
   next()
})